<template>
<view>
   <!-- <swiper autoplay="true" interval="5000" duration="1000" indicator-dots="{{banshow}}">
      <swiper-item wx:for="{{banlist}}" wx:key="integral_id">
         <image src='{{item.pic}}' class='swiper-img' data-img='{{item.pic}}' catchtap='lookPic'></image>
      </swiper-item>
   </swiper> -->
   <image class="topimg" :data-img="img" @tap.stop="lookPic" :src="img"></image>
   <view class="name">{{shoplist.goods_name}}</view>
   <view class="jifen">{{shoplist.price}}积分</view>
   <rich-text :nodes="shoplist.desc"></rich-text>
   <view class="bai"></view>
   <view class="bottom">
      <view class="index" @tap="index">
         <image src="/static/remao_shop/img/shouye_icon.png"></image>
         <view>主页</view>
      </view>
      <button hover-class="none" @tap="IntegralOrder">立即兑换</button>
   </view>

</view>
</template>

<script>
// hotmall/packageB/IntegralDetailsOfCommodities/IntegralDetailsOfCommodities.js
var app = getApp();
import api from "../../../api";

export default {
  data() {
    return {
      banshow: false,
      userId: '',
      banlist: [],
      shoplist: [],
      integral_id: '',
      img: ''
    };
  },

  components: {},
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.getStorage({
      key: 'userId',
      success: res => {
        console.log(res);
        this.setData({
          userId: res.data
        });
        console.log(this.userId);
        this.getList();
      }
    });
    console.log(options);
    this.integral_id = options.integral_id;
    this.setData({
      img: options.img
    });
    console.log(this.img);
    console.log(this.integral_id);
    console.log(this.userId);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.getList();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  methods: {
    getList: function () {
      app.globalData.request({
        url: api.default.integral_integraldetail,
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          uid: this.userId,
          integral_id: this.integral_id
        },
        method: 'POST',
        success: res => {
          console.log(res);
          this.setData({
            shoplist: res.integral_detail //  banlist: res.integral_detail.imgs

          }); // if (res.integral_detail.imgs.length > 1) {
          //    this.setData({
          //       banshow: true
          //    })
          // }
        }
      });
    },
    dhList: function () {
      app.globalData.request({
        url: api.default.integral_integralorder,
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          uid: this.userId,
          integral_id: this.integral_id
        },
        method: 'POST',
        success: res => {
          console.log(res);
          this.setData({});

          if (res.status == 0) {
            wx.showToast({
              title: res.msg,
              icon: 'none'
            });
          } else {
            wx.navigateTo({
              url: '../IntegralOrder/IntegralOrder?uid=' + this.userId + '&integral_id=' + this.integral_id
            });
          }
        }
      });
    },
    // 预览图片
    lookPic: function (e) {
      console.log(e);
      console.log(e.currentTarget.dataset.img);
      var picList = [];
      picList.push(e.currentTarget.dataset.img);
      console.log(picList);
      wx.previewImage({
        current: picList[0],
        // 当前显示图片的http链接
        urls: picList // 需要预览的图片http链接列表

      });
    },
    IntegralOrder: function () {
      this.dhList();
    },
    //跳转主页
    index: function (event) {
      wx.switchTab({
        url: '../../pages/index/index'
      });
    }
  }
};
</script>
<style>
@import "./IntegralDetailsOfCommodities.css";
</style>